using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

namespace DD.Data.SQL
{
    public class CategoryManager
    {
        public static DataSet GetCategories()
        {
            SqlConnection conn = new SqlConnection();
            conn = DD.Data.SQL.DataManager.GetConnection();

            SqlCommand com = new SqlCommand("GET_CATEGORIES", conn);
            com.CommandType = CommandType.StoredProcedure;
            

            SqlDataAdapter da = new SqlDataAdapter(com);
            DataSet ds = new DataSet();

            da.Fill(ds);

            return ds;

            
        }

        

        public static int CountProductsCategoryAssingedTo(int catid)
        {
            SqlConnection conn = new SqlConnection();
            conn = DD.Data.SQL.DataManager.GetConnection();

            SqlCommand com = new SqlCommand("sp_DD_CHECK_ASSIGNED_CATEGORY", conn);
            com.CommandType = CommandType.StoredProcedure;

            SqlParameter param1 = new SqlParameter("@CID", catid);
            param1.SqlDbType = SqlDbType.Int;

            SqlParameter param2 = new SqlParameter("@COUNT", SqlDbType.Int);
            param2.Direction = ParameterDirection.Output;

            com.Parameters.Add(param1);
            com.Parameters.Add(param2);

            conn.Open();
            com.ExecuteNonQuery();
            conn.Close();

            return (int)param2.Value;
            
            
        }
    }
}
